GError **error)
{
gboolean val;
-
if (!ot_parse_boolean (value, &val, error))
return FALSE;
-
- opt_disable_fsync = !val;
+ opt_disable_fsync = !val;
return TRUE;
}
GCancellable *cancellable,
GError **error)
{
- gboolean ret = FALSE;
- g_autofree char *contents = NULL;
- g_autoptr(GFile) file = NULL;
- char **lines = NULL;
-
- file = g_file_new_for_path (path);
- if (!g_file_load_contents (file, cancellable, &contents, NULL, NULL, error))
- goto out;
+ g_autofree char *contents =
+ glnx_file_get_contents_utf8_at (AT_FDCWD, path, NULL, cancellable, error);
+ if (!contents)
+ return FALSE;
- lines = g_strsplit (contents, "\n", -1);
+ g_auto(GStrv) lines = g_strsplit (contents, "\n", -1);
for (char **iter = lines; iter && *iter; iter++)
{
/* skip empty lines at least */
continue;
if (!cb (*iter, cbdata, error))
- goto out;
+ return FALSE;
}
- ret = TRUE;
-out:
- g_strfreev (lines);
- return ret;
+ return TRUE;
}
static gboolean
GError **error)
{
GHashTable *files = data;
- const char *spc;
- guint mode_add;
-
- spc = strchr (line, ' ');
+ const char *spc = strchr (line, ' ');
if (spc == NULL)
- {
- return glnx_throw (error, "Malformed statoverride file (no space found)");
- }
+ return glnx_throw (error, "Malformed statoverride file (no space found)");
- mode_add = (guint32)(gint32)g_ascii_strtod (line, NULL);
+ guint mode_add = (guint32)(gint32)g_ascii_strtod (line, NULL);
g_hash_table_insert (files, g_strdup (spc + 1),
GUINT_TO_POINTER((gint32)mode_add));
return TRUE;
GCancellable *cancellable,
GError **error)
{
- g_autofree char *input = NULL;
- g_autofree char *output = NULL;
- gboolean ret = FALSE;
- g_autoptr(GString) bodybuf = NULL;
- char **lines = NULL;
- int i;
-
- input = g_strdup_printf ("\n"
+ g_autofree char *input = g_strdup_printf ("\n"
"# Please enter the commit message for your changes. The first line will\n"
"# become the subject, and the remainder the body. Lines starting\n"
"# with '#' will be ignored, and an empty message aborts the commit."
*subject = NULL;
*body = NULL;
- output = ot_editor_prompt (repo, input, cancellable, error);
+ g_autofree char *output = ot_editor_prompt (repo, input, cancellable, error);
if (output == NULL)
- goto out;
+ return FALSE;
- lines = g_strsplit (output, "\n", -1);
- for (i = 0; lines[i] != NULL; i++)
+ g_auto(GStrv) lines = g_strsplit (output, "\n", -1);
+ g_autoptr(GString) bodybuf = NULL;
+ for (guint i = 0; lines[i] != NULL; i++)
{
g_strchomp (lines[i]);
}
if (!*subject)
- {
- g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Aborting commit due to empty commit subject.");
- goto out;
- }
+ return glnx_throw (error, "Aborting commit due to empty commit subject.");
if (bodybuf)
{
- *body = g_string_free (bodybuf, FALSE);
+ *body = g_string_free (g_steal_pointer (&bodybuf), FALSE);
g_strchomp (*body);
- bodybuf = NULL;
}
- ret = TRUE;
-
-out:
- g_strfreev (lines);
- return ret;
+ return TRUE;
}
static gboolean
GVariant **out_metadata,
GError **error)
{
- gboolean ret = FALSE;
- char **iter;
- g_autoptr(GVariantBuilder) builder = NULL;
-
- builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
+ g_autoptr(GVariantBuilder) builder =
+ g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
- for (iter = strings; *iter; iter++)
+ for (char ** iter = strings; *iter; iter++)
{
- const char *s;
- const char *eq;
- g_autofree char *key = NULL;
-
- s = *iter;
-
- eq = strchr (s, '=');
+ const char *s = *iter;
+ const char *eq = strchr (s, '=');
if (!eq)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Missing '=' in KEY=VALUE metadata '%s'", s);
- goto out;
- }
-
- key = g_strndup (s, eq - s);
+ return glnx_throw (error, "Missing '=' in KEY=VALUE metadata '%s'", s);
+ g_autofree char *key = g_strndup (s, eq - s);
g_variant_builder_add (builder, "{sv}", key,
g_variant_new_string (eq + 1));
}
- ret = TRUE;
- *out_metadata = g_variant_builder_end (builder);
- g_variant_ref_sink (*out_metadata);
- out:
- return ret;
+ *out_metadata = g_variant_ref_sink (g_variant_builder_end (builder));
+ return TRUE;
}
gboolean
&detached_metadata, error))
goto out;
}
-
+
if (!(opt_branch || opt_orphan))
{
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,